package com.xiaochong.tir.apiservice.component;

import akka.actor.UntypedActor;
import com.alibaba.fastjson.JSON;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.apiservice.util.SpringContextUtil;
import com.xiaochong.tir.common.data.hbasepo.CmcCurrencyInfo;
import com.xiaochong.tir.common.data.hbasepo.MoreThanPercentageSixChange;
import com.xiaochong.tir.common.util.CollectionUtil;
import com.xiaochong.tir.common.util.DateUtils;
import com.xiaochong.tir.common.util.LogTraceKeysUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * Created by wujiaxing on 2018/5/7.
 */
public class AkkaMoreThanPercentageSix extends UntypedActor {


    private CoinMarketCapDataComponent coinMarketCapDataComponent =
            (CoinMarketCapDataComponent) SpringContextUtil.getBean("coinMarketCapDataComponent");


    @Override
    public void onReceive(Object o) {
        LogTrace.beginTrace("超过6%计算");
        Object o1 = ((Object[]) o)[0];
        Map<String, CmcCurrencyInfo> cmcInfoMap = (Map<String, CmcCurrencyInfo>) o1;
        LogTrace.info(LogTraceKeysUtils.AKKA_MORE_THAN_PERCENTAGE_SIX_TITLE, LogTraceKeysUtils.DATA,"定时任务准备计算超过6%");
        try{
            LogTrace.info(LogTraceKeysUtils.AKKA_MORE_THAN_PERCENTAGE_SIX_TITLE, LogTraceKeysUtils.DATA,"定时任务准备计算超过6%"+LocalDateTime.now().getHour());
            if(LocalDateTime.now().getHour()>=9/*LocalDateTime.now().getHour()>=3*/){
                Map<String, MoreThanPercentageSixChange> moreThanPercentageSixChangeList =
                        coinMarketCapDataComponent.getMoreThanPercentageSixChangeList(DateUtils.getCurrentDateString());
                if(CollectionUtil.isBlank(moreThanPercentageSixChangeList)){
                    LogTrace.info(LogTraceKeysUtils.AKKA_MORE_THAN_PERCENTAGE_SIX_TITLE, LogTraceKeysUtils.DATA,"定时任务超过6%计算开始");
                    List<MoreThanPercentageSixChange> sixChangeList =
                            coinMarketCapDataComponent.saveMoreThanPercentageSixChange(cmcInfoMap);
                    LogTrace.info(LogTraceKeysUtils.AKKA_MORE_THAN_PERCENTAGE_SIX_TITLE, LogTraceKeysUtils.DATA, "定时任务超过6%计算完成");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error(e.getMessage(), e);
        }

        LogTrace.endTrace();
    }
}
